package top.deepdesigner.controller.market;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.deepdesigner.pojo.DtsRegion;
import top.deepdesigner.service.DtsRegionService;
import top.deepdesigner.util.ResponseUtil;
import top.deepdesigner.vo.CommonListVO;

import java.util.HashMap;
import java.util.List;

/**
 * 地区管理 <br/>
 * Created with IntelliJ IDEA. <br/>
 * Project Name: shop_manage <br/>
 * Author: duanruiqing <br/>
 * DateTime: 2022/9/21 星期三 22:35:33 <br/>
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/region")
public class RegionController {

  @Autowired
  private DtsRegionService regionService;


  @GetMapping("/list")
  public Object list(@RequestParam HashMap<String, Object> params,
                     @RequestParam(defaultValue = "") String name,
                     @RequestParam(defaultValue = "") Integer code) {
    Integer page = Integer.parseInt((String) params.get("page"));
    Integer limit = Integer.parseInt((String) params.get("limit"));

    CommonListVO<DtsRegion> regionListVO = new CommonListVO<>();
    //获取分页用户角色数量
    Long count = regionService.getRegionCount();
    List<DtsRegion> dtsRegion = regionService.getRegionList(page, limit, name, code);
    regionListVO.setTotal(count);
    regionListVO.setItems(dtsRegion);
    return ResponseUtil.ok(regionListVO);
  }
}
